﻿@model  DataAccess.Models.AgencyUsers
@{
    //List<DataAccess.Models.Alimama> alimamas = new List<DataAccess.Models.Alimama>();
    //alimamas = (List<DataAccess.Models.Alimama>)ViewBag.Alimamas;

    //DataAccess.Models.AgencyUsers superior = (DataAccess.Models.AgencyUsers)ViewBag.superior;
    //DataAccess.Models.AgencyUsers onthe_superior = (DataAccess.Models.AgencyUsers)ViewBag.onthe_superior;

    //List<DataAccess.Models.AgencyUsers> users = new List<DataAccess.Models.AgencyUsers>();
    //users = (List<DataAccess.Models.AgencyUsers>)ViewBag.Users;
} 

<script src="~/Scripts/plugins/jquery.min.js"></script>
<script src="~/Scripts/plugins/layer/layer.min.js"></script>

@section Scripts{
    <script type="text/javascript">

        var index = parent.layer.getFrameIndex(window.name);

        $(function () {

            $("#cancel").click(function () {
                //parent.$("#handle_status").val('1112');
                //alert(parent.$("#handle_status").val());
                //parent.location.reload();
                parent.layer.close(index);
            });

            //$(".chosen-select").chosen();

            $("#submit").bind("click", Save);

        })

        function Save() {

            //权限
            var permission = '';

            $('input[name=ckPerm]:checked').each(function () {
                permission+=$(this).val()+','
            })
            
           
            var username = $.trim($("input[name=username]").val());
            if (username.length == 0) {
                layer.tips('用户名不能为空！', 'input[name=username]', { tips: [2, '#78BA32'] });
                return false;
            }

            var re = /^[0-9a-zA-Z]*$/;
            if (!re.test(username))
            {
                layer.tips('用户名只能使用字母或数字', 'input[name=username]', { tips: [2, '#78BA32'] });
                return false;
            }


            var password = $.trim($("input[name=password]").val());
            if (password.length == 0) {
                layer.tips('密码不能为空！', 'input[name=password]', { tips: [2, '#78BA32'] });
                return false;
            }

            var nickname = $.trim($("input[name=nickname]").val());
            if (nickname.length == 0) {
                layer.tips('昵称不能为空！', 'input[name=nickname]', { tips: [2, '#78BA32'] });
                return false;
            }
            var tel = $.trim($("input[name=tel]").val());
            //if (tel.length == 0) {
            //    layer.tips('手机不能为空！', 'input[name=tel]', { tips: [2, '#78BA32'] });
            //    return false;
            //} else
                //if (!tel.match(/^(((13[0-9]{1})|159|153|17[0-9]|18[0-9])+\d{8})$/)) {
                //layer.tips('手机号码格式不正确！', 'input[name=tel]', { tips: [2, '#78BA32'] });
                //return false;
            // }

            var alimamaid = $('#alimamaid').val();
            
            if (alimamaid == null || alimamaid.length == 0) {
                
                //layer.tips('请选择联盟账号', 'input[name=alimamaid]', { tips: [2, '#78BA32'] });
                alert("请选择联盟账号，如果没有请先登录妈妈同步机器人")
                return false;
            }
            var commission = $.trim($("input[name=commission]").val());
            if (commission.length == 0) {
                layer.tips('请输入分成比例！', 'input[name=commission]', { tips: [2, '#78BA32'] });
                return false;
            }


            var superior = $('#superior').val();
            var superior_commission = $('#superior_commission').val();

            var onthe_superior = $('#onthe_superior').val();
            var onthe_superior_commission = $('#onthe_superior_commission').val();


            var state = $("#state").val();
            var id = $("#id").val();
            var remark = $("#remark").val();

            common.invokeApi(
                "POST",
                "/editedAgencyUser.html",
                //"id=" + id + "&state=" + state + "&username=" + username + "&password=" + password + "&nickname=" + nickname + "&tel=" + tel,
                {
                    id: id, state: state, username: username, password: password, nickname: nickname, tel: tel, remark: remark,
                    alimamaid: alimamaid, commission: commission, superior: superior, superior_commission: superior_commission,
                    onthe_superior: onthe_superior, onthe_superior_commission: onthe_superior_commission, permission: permission
                },
                function () { },
                function (data) {
                    common.msg(data.Message, 1, function () {
                        //parent.location.reload();
                        //parent.layer.close(index);
                        window.location.href = "/AgencyUsers.html";
                    }); 
                },
                function (data) {
                    common.msg(data.Message, 2, function () { });
                },
                function () { }
                );
        }



    </script>
    <script src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Scripts/plugins/validate/messages_zh.min.js"></script>
    <script src="~/Scripts/sys/lib/common_raw.js"></script>
}





<div class="row">
    <div class="col-lg-12">
        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><a href="#">代理管理</a></li>
                    <li class="active"><span>代理账号新增</span></li>
                </ol>
                <h1>代理账号新增修改</h1>
            </div>
        </div>

        <form   role="form" method="post">

            <input type="hidden" id="id" name="id" value="@(Model.id)" />
            <div class="row">
                <div class="col-lg-12">
                    <div class="main-box">
                        <header class="main-box-header clearfix">
                            <h2>代理账号编辑</h2>
                        </header>
                        <div class="main-box-body clearfix">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDate">用户名:</label>
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="fa fa-user"></i></span>
                                                <input type="text" id="username" name="username" max="10" value="@(Model.username)" @(Model.id != 0 ? "readonly=\"readonly\"" : "") class="form-control" placeholder="输入用户名">
                                            </div>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateRange">姓名:</label>
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="fa fa-reorder"></i></span>
                                                <input type="text" id="nickname" name="nickname" value="@(Model.nickname)" maxlength="6" class="form-control" placeholder="输入姓名">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateComponent">密码:</label>
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                                <input type="text" id="password" name="password" maxlength="10" value="@(string.IsNullOrEmpty(Model.password)?"":XYD.Common.EncodeSecurity.DecryptString( Model.password))" class="form-control" placeholder="输入密码">

                                            </div>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="timepicker">手机:</label>
                                            <div class="input-group ">
                                                <span class="input-group-addon"><i class="fa fa-phone"></i></span>
                                                <input type="text" id="tel" name="tel" value="@(Model.tel)" maxlength="11" class="form-control" placeholder="输入手机">
                                            </div>
                                        </div>
                                    </div>
                                </div>




                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateComponent">状态:</label>
                                            <select class="form-control" name="state" id="state">
                                                <option value="1" @(Model.state == 1 ? "selected" : "")>启用</option>
                                                <option value="0" @(Model.state == 0 ? "selected" : "")>禁用</option>
                                            </select>

                                        </div>
                                    </div>
                                    <div class="row">


                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateComponent">联盟账号:</label>
                                            <div class="input-group">
                                                <span class="input-group-addon"><i class="fa fa-th"></i></span>
                                                @*<select class="form-control" name="alimamaid" id="alimamaid">
                                @{
                                    foreach (var item in alimamas)
                                    {
                                        <option value="@(item.alimamaid)" @(item.alimamaid == Model.alimamaid ? "selected" : "")>@(item.username)</option>
                                    }
                                }
                            </select>*@

                                                @Html.DropDownListFor(l => l.alimamaid, ViewBag.Alimamas as IEnumerable<SelectListItem>, new { @class = "chosen-select form-control", style = "width:100%;" })
                                            </div>

                                        </div>


                                    </div>
                                </div>


                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="timepicker">备注:</label>
                                            <div class="input-group ">
                                                <span class="input-group-addon"><i class="fa fa-bookmark-o"></i></span>
                                                <input type="text" id="remark" name="remark" value="@(Model.remark)" maxlength="100" class="form-control" placeholder="输入备注">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="timepicker">分佣比例 %:</label>
                                            <div class="input-group ">
                                                <span class="input-group-addon">%</span>
                                                <input type="text" class="form-control" value="@(Model.commission)" id="commission" name="commission">
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateComponent">上级代理:</label>
                                            <div class="input-group">
                                                @*@{
                                if (Model.superior != 0)
                                {
                                    <input type="text" value="@(superior.username)" class="form-control" readonly="readonly">
                                    <input type="hidden" id="superior" name="superior" value="@(superior.id)" />
                                }
                                else
                                {
                                    <select id="superior" name="superior" data-placeholder="选择代理..." class="chosen-select form-control" style="width:100%;">
                                        <option value="0" @(0 == Model.superior ? "selected" : "")>选择代理...</option>
                                        @{
                                    foreach (var item in users.FindAll(p => p.id != Model.id))
                                    {
                                        <option value="@(item.id)" @(item.id == Model.superior ? "selected" : "")>@(item.username)</option>
                                    }
                                        }
                                    </select>
                                }
                            }*@

                                                @Html.DropDownListFor(l => l.superior, (List<SelectListItem>)ViewBag.superiorSLI, new { data_placeholder = "选择代理...", @class = "chosen-select form-control", style = "width:100%;" })

                                                <span class="input-group-addon"><i class="fa fa-th"></i></span>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="timepicker">上级佣金 %:</label>
                                            <div class="input-group ">
                                                <span class="input-group-addon">%</span>
                                                <input type="text" class="form-control" value="@( Model.superior_commission   )" id="superior_commission" name="superior_commission">
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="datepickerDateComponent">上上级代理:</label>
                                            <div class="input-group">
                                                @*@{
                                if (Model.onthe_superior != 0)
                                {
                                    <input type="text" value="@(onthe_superior.username)" class="form-control" readonly="readonly">
                                    <input type="hidden" id="onthe_superior" name="onthe_superior" value="@(onthe_superior.id)" />
                                }
                                else
                                {
                                    <select id="onthe_superior" name="onthe_superior" data-placeholder="选择代理..." class="chosen-select form-control" style="width:100%;">
                                        <option value="0" @(0 == Model.onthe_superior ? "selected" : "")>选择代理...</option>

                                        @{


                                    foreach (var item in users.FindAll(p => p.id != Model.id))
                                    {
                                        <option value="@(item.id)" @(item.id == Model.onthe_superior ? "selected" : "")>@(item.username)</option>
                                    }
                                        }
                                    </select>
                                }

                            }*@
                                                @Html.DropDownListFor(l => l.onthe_superior, (List<SelectListItem>)ViewBag.onthe_superiorSLI, new { data_placeholder = "选择代理...", @class = "chosen-select form-control", style = "width:100%;" })
                                                <span class="input-group-addon"><i class="fa fa-th"></i></span>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label for="timepicker">上上级佣金 %:</label>
                                            <div class="input-group ">
                                                <span class="input-group-addon">%</span>
                                                <input type="text" class="form-control" value="@(  Model.onthe_superior_commission )" id="onthe_superior_commission" name="onthe_superior_commission">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-6">
                                    <div class="row">
                                        <div class="form-group col-md-12">
                                            <label>开启权限</label>
                                            <br>
                                            <div class="checkbox-nice checkbox-inline">
                                               
                                                @if(Model.permission.Contains("1")){
                                                 <input type="checkbox" id="ck_shopZL" name="ckPerm" value="1" checked>
                                                
                                                }
                                                else
                                                { 
                                                      <input type="checkbox" id="ck_shopZL" name="ckPerm" value="1" >
                                                }

                                                <label for="ck_shopZL">
                                                    商品转链
                                                </label>
                                            </div>
                                           
                                        </div>
                                        </div>
                                    </div>
                                        <div class="form-group">
                                            <div class="col-lg-offset-2 col-lg-10">
                                                <button type="button" id="submit" class="btn btn-success">保 存</button>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                </div>
            </div>


</form>





</div>
</div>